<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2024-07-26 08:45:52
 * @LastEditors: zss
 * @LastEditTime: 2025-05-30 11:46:23
-->

<template>
  <div class="init-container">
    <div class="mask-container" v-if="isMask"></div>
    <!-- <Button type="primary" @click="openBtnsModal">{{
      $srv.getI18nByValue('打开弹窗')
    }}</Button> -->
    <div class="top-info">
      <Button type="primary" @click="openBeforeLoadModal">上料前操作</Button>
      <Button type="primary" @click="openSpecialModal">特殊操作</Button>
      <div
        class="top-message"
        :class="{ 'top-message-error': tempMessage !== '' }"
      >
        {{ tempMessage }}
      </div>
    </div>
    <Split v-model="splitTop" mode="vertical" min="17px" max="17px">
      <template #top>
        <o-base-form :mode="1" ref="bForm"></o-base-form>
      </template>
      <template #bottom>
        <div class="base-grid-container">
          <o-layout
            ref="layout"
            :config="bgConfig"
            :parmas="GT_compBoxInfo"
          ></o-layout>
        </div>
      </template>
    </Split>
    <Modal
      v-model="btnHandleModal"
      draggable
      sticky
      scrollable
      :mask="true"
      mask-closable
      :title="$srv.getI18nByValue('操作')"
    >
      <div class="handle-btn">
        <Button
          :type="btn.type"
          :ghost="btn.ghost"
          :size="btn.size"
          :disabled="btn.disabled"
          :icon="btn.icon"
          v-for="(btn, idx) of btnList"
          :key="idx"
          style="margin: 5px"
          @click="handleBtn(btn)"
          >{{ $srv.getI18nByValue(btn.title) }}</Button
        >
        <p>{{ messageInfo }}</p>
      </div>
    </Modal>
    <before-load-modal
      :visible="beforeLoadModalShow"
      @on-close="closeBeforeLoadModal"
    ></before-load-modal>
    <Modal
      v-model="specialModalShow"
      draggable
      sticky
      scrollable
      :mask="true"
      mask-closable
      :title="$srv.getI18nByValue('特殊操作')"
    >
      <Form :label-width="100">
        <FormItem label="薄片产品标志">
          <InputNumber
            v-model="specialInfo.bopianFlag.value"
            @on-blur="handleBlur(specialInfo.bopianFlag)"
          />
        </FormItem>
        <!-- <FormItem label="组态王工艺号">
          <InputNumber
            v-model="specialInfo.processNum.value"
            @on-blur="handleBlur(specialInfo.processNum)"
          />
        </FormItem> -->
        <!-- <Button @click="testSchde">测试排程</Button> -->
      </Form>
    </Modal>
  </div>
</template>

<script lang="ts">
import {
  I_cmd,
  T_cmd,
  T_srv,
  Tsrv,
  config,
  funInfo,
  handleBtnList,
  ifs,
  vue,
  pLColumns,
  N_cPLDetails
} from './config';
import beforeLoadModal from './beforeLoadModal.vue';
import { N_cStph } from '../homePage/homeCpt/myIndex/types';

@T_srv.comp({ components: { beforeLoadModal } })
export default class cPLDetails extends vue {
  /* 父组件compBoxInfo */
  @T_srv.prop({
    required: false,
    type: Object,
    default: null
  })
  compBoxInfo: ifs.I_compBoxInfo;

  @T_srv.getter('Tanks') tanks: N_cStph.TankConfig[];

  @T_srv.getter('Cranes') cranes: N_cStph.craneControlConfig[];

  /* 组件名 */
  private name: string = 'cPLDetails';

  public funName: string = 'cPLDetails';

  private G_compName: string = this.name;

  /* 组件箱信息对象 */
  private GT_compBoxInfo: ifs.I_compBoxInfo;

  /* 组件箱对象 */
  private GT_compBox: ifs.I_compBox;

  /* 组件箱识别ID */
  private G_compID: string;

  /* 指挥部 */
  private GT_command: I_cmd = new T_cmd();

  /* 遮罩 */
  public isMask: boolean = false;

  private splitTop: number = 0.08;

  public openCompName: string = '';

  public bgConfig: any = {};

  public topTableData: N_cPLDetails.plDetailsRows[] = [];

  private formColumns = pLColumns();

  // 缓存位温度是否达标信息
  private tempMessage = '';

  public formData: N_cPLDetails.cPLDetails['formData'] = {
    id: '',
    physical_produc_line: '',
    produc_line_name: '',
    f_status: 0,
    process_flow_num: '',
    produc_line_num: '',
    'm2o|process_flow_num|process_mgmt|title': '',
    'm2o|physical_produc_line|physical_produc_line_mgmt|f_name': ''
  };

  private btnList: Array<N_cPLDetails.I_handleBtn> = handleBtnList();

  private btnHandleModal: boolean = false;

  private beforeLoadModalShow: boolean = false;

  private specialModalShow: boolean = false;

  private messageInfo = '';

  // 加工中的挂组id
  private processingHangGroupID = '';

  // 挂组物理编号
  private hangGroupNum = '';

  // 当前开启的产线日志信息
  public currentOpenLineInfo = {
    id: '',
    title: ''
  };

  // 获取当前温度达标状态
  private getTempStatus() {
    this.tempMessage = '';
    this.GT_command.fourCacheInfo.forEach((val, key) => {
      // 当前缓存位存在挂组并且温度进线标志为true，记录缓存位
      if (Number(val.hangGroupId.value) !== 0 && val.tempIsSatisfied.value) {
        this.tempMessage += key;
      }
    });
    if (this.tempMessage !== '') {
      this.tempMessage += '温度未达标，不进线';
    }
  }

  private specialInfo = {
    bopianFlag: {
      code: 'my1793',
      value: 0,
      conversionRate: 1
    },
    processNum: {
      code: '',
      value: 0,
      conversionRate: 1
    }
  };

  // 监听挂组状态
  @T_srv.watch('topTableData', { deep: true })
  watchHangGroupStatus(val: N_cPLDetails.plDetailsRows[]) {
    if (!val || !Array.isArray(val)) {
      return;
    }
    const readyData = val.filter(el => el.f_status === 2);
    // 无准备就绪挂组时不做处理
    if (readyData.length === 0) {
      return;
    }
    this.GT_command.beforeSchedule(val);
  }

  created() {
    // 如果父组件没有传参，那就产生一个
    this.GT_compBoxInfo = Tsrv.getCompInfo(this.compBoxInfo);
    this.G_compID = this.GT_compBoxInfo.compID;
    this.GT_compBox = this.GT_compBoxInfo.TcompBox;
    this.GT_command.init(this, this.GT_compBoxInfo);
    this.init();
  }

  mounted() {
    /* 向父组件发送实例 */
    this.GT_compBox.addCompMergeName(this.G_compID, this.G_compName, this);
    this.$emit('compBoxInfo', this.GT_compBoxInfo);
    const layoutComp: any = this.$refs.layout;
    // 产线明细管理表格实例
    this.GT_command.topBaseGrid =
      layoutComp.$children[0].$children[0].$children[0];

    this.receiveEvent();
    setTimeout(() => {
      this.loadForm();
    }, 1000);
    this.GT_command.getappNums();
  }

  // 接收事件
  private receiveEvent() {
    this.startPLine();
    this.stopPLine();
    this.techFixed();
    this.plcRestart();
  }

  // 产线开启
  private startPLine() {
    this.$bus.$on('MY_RUN_PRODUC_LINE', (msg: any) => {
      this.formData = msg;
      this.formData.f_status = 1; // 0-停止 1-运行

      // 过滤当前产线挂组信息
      this.GT_command.topBaseGrid.GT_editor.addInitFilter({
        field: 'master_bill_id',
        value: this.formData.id
      });
      this.GT_command.topBaseGrid.GT_editor.loadTableData();
      this.addEcCodeList();
      this.GT_command.startTask();
      this.$bus.$on('__WS_SUBSCRIPTION__', (m: ifs.I_receWsMsgParams) => {
        this.GT_command.receiveScadaData(m);
      });
      this.sendLogOut(`${this.formData.produc_line_name}产线开启`);
      // 记录产线日志
      this.recordPLlog(true);
    });
  }

  // 添加需要读取的电控点
  private addEcCodeList() {
    this.GT_command.ecDetCodeList = [];
    // 上料完成
    this.GT_command.ecDetCodeList.push(...this.GT_command.hangGroupFlag);
    // 加工完毕
    const data = this.GT_command.writeHangGroup.concat(
      this.GT_command.writeHangGroupId
    );
    this.GT_command.ecDetCodeList.push(...data);

    // 自动化生产
    const codes = ['my800', 'my818', 'my498', 'my499', 'my801', 'my819'];
    this.GT_command.ecDetCodeList.push(...codes);
    // 缓存位状态
    this.GT_command.fourCacheInfo.forEach((value, _) => {
      this.GT_command.ecDetCodeList.push(value.hangGroupId.code);
      this.GT_command.ecDetCodeList.push(value.hangGroupStatus.code);
      this.GT_command.ecDetCodeList.push(value.tempIsSatisfied.code);
    });
  }

  // 产线关闭
  private stopPLine() {
    this.$bus.$on('MY_STOP_PRODUC_LINE', (msg: any) => {
      this.GT_command.stopTask();
      // 产线暂停关闭scada订阅
      this.$bus.$off('__WS_SUBSCRIPTION__');
      this.sendLogOut(`${this.formData.produc_line_name}产线关闭`);
      this.recordPLlog(false);
    });
  }

  // 工艺已定事件
  private techFixed() {
    this.$bus.$on('MY_RECEIVE_ECODES', (params: any) => {
      const data: N_cPLDetails.I_receiveParams = JSON.parse(wUnZipStr(params));

      // params = {currentID: 123, ecDetCodes: [{ecDetCode: 'my1809', value: 'true'}]};
      this.GT_command.submitPlc(data);
      // 判断上一次校验是否返回结果，返回结果则提交plc，否者放入系统等待校验
      // if (this.GT_command.legalStatus !== N_cPLDetails.V_reqStatus.RUNNING) {
      // } else {
      //   // 放入系统等待校验
      //   this.GT_command.waitPlcData.push(data);
      // }
    });
  }

  // plc断连或重启事件
  private plcRestart() {
    this.$bus.$on(
      '__PLC_CONNSTATE__',
      (data: { connState: boolean; ecBoxName: string }) => {
        if (data.ecBoxName === 'mianyang') {
          if (data.connState) {
            if (!this.GT_command.isOpenTask) {
              this.GT_command.startTask();
            }
          } else {
            this.GT_command.stopTask();
          }
        }
      }
    );
  }

  // 记录产线日志
  private recordPLlog(isStart: boolean) {
    if (isStart) {
      const nowDate = Tsrv.utils.toDateString(new Date());
      this.currentOpenLineInfo.id = Tsrv.getSnowIDFmtStr();
      this.currentOpenLineInfo.title = `${this.formData.produc_line_num}-${nowDate}`;
      const data = [
        [
          {
            field: 'id',
            value: this.currentOpenLineInfo.id
          } as ifs.I_fv,
          {
            field: 'production_line',
            value: this.formData.id
          } as ifs.I_fv,
          {
            field: 'title',
            value: this.currentOpenLineInfo.title
          } as ifs.I_fv
        ]
      ];
      this.GT_command.addTableData(this.GT_command.tableName.pLLog, data);
    } else {
      const data = [
        [
          {
            field: 'id',
            value: this.currentOpenLineInfo.id
          } as ifs.I_fv,
          {
            field: 'end_time',
            value: Tsrv.utils.toDateString(new Date())
          } as ifs.I_fv
        ]
      ];
      this.GT_command.modifyData(
        this.GT_command.tableName.pLLog,
        this.GT_command.filterName.ID,
        data
      ).then(success => {
        if (success) {
          const rows = this.GT_command.topBaseGrid.cloudData.filter(
            el => el.f_status === '5'
          );
          if (!Tsrv.noValue(rows)) {
            const rowDatas = [];
            rows.forEach(el => {
              const row = [
                {
                  field: 'id',
                  value: Tsrv.getSnowIDFmtStr()
                } as ifs.I_fv,
                {
                  field: 'master_bill_id',
                  value: el.id
                } as ifs.I_fv,
                {
                  field: 'title',
                  value: '挂组状态异常，产线关闭该挂组仍处于加工状态'
                } as ifs.I_fv
              ];
              rowDatas.push(row);
            });
            this.GT_command.addTableData(
              this.GT_command.tableName.pLLog,
              rowDatas
            );
          }
        }
      });
    }
  }

  public sendLogOut(logData: Array<object | string> | object | string) {
    this.$bus.$emit('_LOG_OUTPUT_', logData);
  }

  // 产线关闭前动作
  private beforeClose() {
    // 停止定时任务
    this.GT_command.stopTask();
    // 移除所有排程
    // if (this.GT_command.schedulingStatus === N_cPLDetails.V_reqStatus.RUNNING) {
    //   this.GT_command.removeAllTask();
    // }
    // 将产线管理状态设为暂停
    if (this.formData.id) {
      const data = [
        [
          {
            field: 'id',
            value: this.formData.id
          } as ifs.I_fv,
          {
            field: 'f_status',
            value: 0
          } as ifs.I_fv
        ]
      ];
      this.GT_command.modifyData(
        this.GT_command.tableName.pLine,
        this.GT_command.filterName.ID,
        data
      ).then(success => {
        if (success) {
          // 通过发事件的方式，让产线管理表自动刷新
          this.GT_command.sendBusEvent(
            this.GT_command.commonEvent.lMEvent,
            this.GT_command.eventArg
          );
          this.recordPLlog(false);
        }
      });
    }
    // 停止监听事件

    this.$bus.$off('MY_STOP_PRODUC_LINE');
    this.$bus.$off('MY_RUN_PRODUC_LINE');
    this.$bus.$off('MY_RECEIVE_ECODES');
    this.$bus.$off('__WS_SUBSCRIPTION__');
    this.$bus.$off('__PLC_CONNSTATE__');
  }

  destroyed() {
    this.beforeClose();
    /* 注册组件销毁 */
    this.GT_compBox.removeCompMergeName(this.G_compID, this.G_compName);

    if (Tsrv.utils.isEmpty(this.compBoxInfo)) {
      this.GT_compBox.removeCompsWithCompID(this.G_compID);
    } else {
      this.GT_compBox.removeCompsMergeName(this.G_compID, [
        `'${this.G_compName}'`
      ]);
    }
  }

  private init() {
    this.funName = 'cPLDetails'; // 当前配置中的功能名
    const girdConfig = config();
    const gridfunInfo = funInfo();
    Tsrv.store.commit('SET_FUNINFO', {
      key: 'produc_line_detail_mgmt',
      val: gridfunInfo
    });
    this.setTableFilter(girdConfig.config.first.config);
    this.bgConfig = girdConfig;
  }

  private setTableFilter(cf) {
    cf.tableColumns.forEach(el => {
      if (el.field === 'master_bill_id') {
        if (this.formData['id']) {
          el.initFilter = this.formData['id'];
        }
      }
    });
  }

  private loadForm() {
    const form: any = this.$refs['bForm'];
    const formCol = form.transformColumns(this.formColumns);
    form.setColumns(formCol);
    form.setFormData(this.formData);
    form.setModify(false);
  }

  /* 设置组件整体遮罩 */
  public setMask(p: boolean) {
    this.isMask = p;
  }

  public getMask(p: boolean): boolean {
    return this.isMask;
  }

  private openBeforeLoadModal() {
    this.beforeLoadModalShow = true;
  }

  private closeBeforeLoadModal() {
    this.beforeLoadModalShow = false;
  }

  private openSpecialModal() {
    this.specialModalShow = true;
  }

  private closeSpecialModal() {
    this.specialModalShow = false;
  }

  private handleBlur(item: any) {
    const data = [
      {
        ecDetCode: item.code,
        value: ((item.value as number) / item.conversionRate).toString()
      }
    ];

    Tsrv.writePlcData(data).then(_ => {
      Tsrv.readPlcData([item.code]).then(r => {
        if (typeof r === 'boolean') return;
        item.value = r[item.code].v * item.conversionRate;
      });
    });
  }

  // 测试使用 ------------------------------------------

  private handleBtn(btn: N_cPLDetails.I_handleBtn) {
    const key = btn.key;
    // 按钮操作逻辑。。。
    switch (key) {
      case 'loadingCompleted':
        this.loadingCompleted();
        break;
      case 'putIn28Cache':
        this.test1();
        break;
      case 'putIn29Cache':
        this.test2();
        break;
      case 'putIn30Cache':
        this.test3();
        break;
      case 'putIn31Cache':
        this.test4();
        break;
      case 'PLCVerifySuccess':
        this.test5();
        break;
      case 'PLCVerifyFailed':
        this.test6();
        break;
      case 'processing':
        this.test7();
        break;
      case 'sendLog':
        this.test();
        break;
      case 'sendLog1':
        this.test9();
        break;
      case 'sendLog2':
        this.test10();
        break;
      case 'sendLog3':
        this.test11();
        break;
      case 'processed':
        this.test8();
        break;
      case '1Car3Slot':
        this.carFoward1();
        break;
      case '2Car10Slot':
        this.carFoward2();
        break;
      case 'overTempAlarm':
        this.overTempAlarm();
        break;
      case 'relieveAlarm':
        this.relieveAlarm();
        break;
      case '1CarDown':
        this.carDown();
        break;
      default:
        break;
    }
    // this.btnHandleModal = false;
  }

  private testSchde() {
    // 调用api
    const gridFunInfo = Tsrv.getFunInfo(this.GT_command.tableName.pLDetails);
    const list = [
      {
        physicalNum: 250526843,
        status: 0,
        time: '2025-05-26 14:07:37.000'
      },
      {
        physicalNum: 250526865,
        status: 0,
        time: '2025-05-26 13:23:07.000'
      },
      {
        physicalNum: 250526876,
        status: 0,
        time: '2025-05-26 12:29:58.000'
      }
    ];
    const params = () => {
      return {
        funName: 'cPLDetails',
        title: 'customFun',
        from: 'cPLDetails',
        data: {
          hangGroups: list,
          slotTemp: {
            slotName: '585792609139363840', // 铬酸工序id号
            currentTemp: 20
          }
        }
      };
    };
    Tsrv.doEvent('my_simulate_the_process_flow', gridFunInfo, params).then(
      res => {
        const returnData = res.getReturnData('conf');
        const data = returnData.res.data;
        const defaultTime = this.GT_command.changeTimeFormat(
          data.defaultTime,
          1
        );
        const schedulTime = this.GT_command.changeTimeFormat(
          data.scheduleTime,
          1
        );
        console.log(defaultTime, schedulTime);
      }
    );
  }

  private alert() {
    this.$bus.$emit(this.GT_command.commonEvent.receiveAlarmInfo, [
      {
        id: '1',
        content: '测试'
      },
      {
        id: '1',
        content: '测试'
      },
      {
        id: '1',
        content: '测试'
      }
    ]);
  }

  private unAlert() {
    this.$bus.$emit(this.GT_command.commonEvent.receiveAlarmInfo, [
      {
        id: '1',
        content: '测试'
      }
    ]);
  }

  // 上料完成
  private loadingCompleted() {
    this.hangGroupNum = Math.floor(Math.random() * 10000).toString();
    // my855写为true，挂组物理编号，零件编号，零件数量更新，缓存位放入该挂组id
    const writeData = [
      {
        ecDetCode: this.GT_command.hangGroupFlag[0],
        value: 'true'
      },
      {
        ecDetCode: 'my862',
        value: `PART${Math.floor(Math.random() * 10000)}`
      },
      {
        ecDetCode: 'my863',
        value: `PART${Math.floor(Math.random() * 10000)}`
      },
      {
        ecDetCode: 'my864',
        value: `PART${Math.floor(Math.random() * 10000)}`
      },
      {
        ecDetCode: 'my865',
        value: `PART${Math.floor(Math.random() * 10000)}`
      },
      {
        ecDetCode: 'my866',
        value: `PART${Math.floor(Math.random() * 10000)}`
      },
      {
        ecDetCode: 'my357',
        value: this.hangGroupNum.toString()
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '上料完成';
      }
    });
  }

  private carDown() {
    const writeData = [
      {
        ecDetCode: 'my807', // 目标位
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '一车下降';
      }
    });
  }

  private overTempAlarm() {
    const writeData = [
      {
        ecDetCode: 'my511',
        value: 'true'
      },
      {
        ecDetCode: 'my101',
        value: '1000'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '温度报警';
      }
    });
  }

  private relieveAlarm() {
    const writeData = [
      {
        ecDetCode: 'my511',
        value: 'false'
      },
      {
        ecDetCode: 'my101',
        value: '100'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '解除报警';
      }
    });
  }

  private carFoward1() {
    const writeData = [
      {
        ecDetCode: 'my013', // 目标位
        value: '3'
      },
      {
        ecDetCode: 'my804', // 前进
        value: 'true'
      },
      {
        ecDetCode: 'my328', // 工件号
        value: '3091'
      },
      {
        ecDetCode: 'my094', // 温度
        value: '250'
      },
      {
        ecDetCode: 'my082', // 电导率
        value: '250'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '一车3槽';
      }
    });
  }

  private carFoward2() {
    const writeData = [
      {
        ecDetCode: 'my023', // 目标位
        value: '10'
      },
      {
        ecDetCode: 'my823', // 后退
        value: 'true'
      },
      {
        ecDetCode: 'my335', // 工件号
        value: '2880'
      },
      {
        ecDetCode: 'my887', // 接液开关
        value: 'true'
      },
      {
        ecDetCode: 'my933', // 倒水开关
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '2车10槽';
      }
    });
  }

  // 放入28号缓存位
  private test1() {
    const writeData = [
      {
        ecDetCode: 'my353',
        value: this.hangGroupNum.toString()
      },
      {
        ecDetCode: 'my3830',
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '放入28号缓存位';
      }
    });
  }

  // 放入29号缓存位
  private test2() {
    const writeData = [
      {
        ecDetCode: 'my354',
        value: this.hangGroupNum.toString()
      },
      {
        ecDetCode: 'my3831',
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '放入29号缓存位';
      }
    });
  }

  // 放入30号缓存位
  private test3() {
    const writeData = [
      {
        ecDetCode: 'my355',
        value: this.hangGroupNum.toString()
      },
      {
        ecDetCode: 'my3832',
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '放入30号缓存位';
      }
    });
  }

  // 放入31号缓存位
  private test4() {
    const writeData = [
      {
        ecDetCode: 'my356',
        value: this.hangGroupNum.toString()
      },
      {
        ecDetCode: 'my3833',
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '放入31号缓存位';
      }
    });
  }

  // plc检验成功
  private test5() {
    const writeData = [
      {
        ecDetCode: 'my1805',
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '检验成功';
      }
    });
  }

  // plc检验失败
  private test6() {
    const writeData = [
      {
        ecDetCode: 'my1806',
        value: 'true'
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '检验失败';
      }
    });
  }

  // 加工中
  private test7() {
    // 加工中的挂组id变0，缓存位状态变false
    let val1 = ''; // 缓存位状态点
    // let val2 = ''; // 缓存位挂组id点

    const processHg = [];
    this.GT_command.fourCacheInfo.forEach((value, _) => {
      if (
        !Tsrv.noValue(value.hangGroupId.value) &&
        !Tsrv.noValue(value.cacheOrder.value)
      ) {
        processHg.push({
          hangGroupId: value.hangGroupId.value,
          order: value.cacheOrder.value,
          cacheStatusp: value.hangGroupStatus.code,
          hGp: value.hangGroupId.code
        });
      }
    });
    if (processHg.length !== 0) {
      const minOrderItem = processHg.reduce((min, item) => {
        return item.order < min.order ? item : min;
      });
      val1 = minOrderItem.cacheStatusp;
      this.processingHangGroupID = minOrderItem.hangGroupId;
      const writeData = [
        {
          ecDetCode: val1,
          value: 'false'
        },
        {
          ecDetCode: minOrderItem.hGp,
          value: '0'
        }
      ];
      const data = {
        my3830: '28号缓存位',
        my3831: '29号缓存位',
        my3832: '30号缓存位',
        my3833: '31号缓存位'
      };
      this.GT_command.writePlcData(writeData).then(success => {
        if (success) {
          this.messageInfo = `加工中，${data[val1]}已经空闲`;
          this.sendLogOut(this.messageInfo);
        }
      });
    }
  }

  // 加工完毕
  private test8() {
    const writeData = [
      {
        ecDetCode: 'my1808',
        value: 'true'
      },
      {
        ecDetCode: 'my1809',
        value: this.processingHangGroupID.toString()
      }
    ];
    this.GT_command.writePlcData(writeData).then(success => {
      if (success) {
        this.messageInfo = '加工完毕';
      }
    });
  }

  private openBtnsModal() {
    this.btnHandleModal = true;
  }

  private closeBtnsModal() {
    this.btnHandleModal = true;
  }

  private test() {
    const data = [
      {
        appNum: 200,
        dataType: '0x03',
        value: 10
      },
      {
        appNum: 201,
        dataType: '0x03',
        value: 10
      },
      {
        appNum: 202,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 203,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 204,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 205,
        dataType: '0x03',
        value: 10
      },
      {
        appNum: 130,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 131,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 132,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 133,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 134,
        dataType: '0x03',
        // value: Number(this.processingHangGroupID)
        value: 3059
      },
      {
        appNum: 135,
        dataType: '0x03',
        value: 0
      }
    ];
    const msg: any = {
      cmd: 0,
      m: { t: 7, d: data }
    };
    this.GT_command.receiveScadaData(msg);
    // const aaa = JSON.stringify({
    //   userMsgs: [
    //     {
    //       toUserNo: 'dev07',
    //       toClientID: '123',
    //       msg: {
    //         cmd: 0,
    //         m: { t: 7, d: data }
    //       }
    //     }
    //   ]
    // });
    // vue.prototype.$socket.send(aaa);
  }

  private test9() {
    const data = [
      {
        appNum: 220,
        dataType: '0x03',
        value: 2
      },
      {
        appNum: 221,
        dataType: '0x03',
        value: 20
      },
      {
        appNum: 222,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 223,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 130,
        dataType: '0x03',
        value: 2
      },
      {
        appNum: 131,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 132,
        dataType: '0x03',
        value: 2
      },
      {
        appNum: 133,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 134,
        dataType: '0x03',
        // value: Number(this.processingHangGroupID)
        value: 3059
      },
      {
        appNum: 135,
        dataType: '0x03',
        value: 0
      }
    ];
    const msg: any = {
      cmd: 0,
      m: { t: 7, d: data }
    };
    this.GT_command.receiveScadaData(msg);
    // const aaa = JSON.stringify({
    //   userMsgs: [
    //     {
    //       toUserNo: 'dev07',
    //       toClientID: '123',
    //       msg: {
    //         cmd: 0,
    //         m: { t: 7, d: data }
    //       }
    //     }
    //   ]
    // });
    // vue.prototype.$socket.send(aaa);
  }

  private test10() {
    const data = [
      {
        appNum: 200,
        dataType: '0x03',
        value: 10
      },
      {
        appNum: 201,
        dataType: '0x03',
        value: 10
      },
      {
        appNum: 202,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 203,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 204,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 205,
        dataType: '0x03',
        value: 10
      },
      {
        appNum: 130,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 131,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 132,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 133,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 134,
        dataType: '0x03',
        // value: Number(this.processingHangGroupID)
        value: 2993
      },
      {
        appNum: 135,
        dataType: '0x03',
        value: 0
      }
    ];
    const msg: any = {
      cmd: 0,
      m: { t: 7, d: data }
    };
    this.GT_command.receiveScadaData(msg);
  }

  private test11() {
    const data = [
      {
        appNum: 220,
        dataType: '0x03',
        value: 2
      },
      {
        appNum: 221,
        dataType: '0x03',
        value: 20
      },
      {
        appNum: 222,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 223,
        dataType: '0x03',
        value: 1
      },
      {
        appNum: 130,
        dataType: '0x03',
        value: 2
      },
      {
        appNum: 131,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 132,
        dataType: '0x03',
        value: 2
      },
      {
        appNum: 133,
        dataType: '0x03',
        value: 0
      },
      {
        appNum: 134,
        dataType: '0x03',
        // value: Number(this.processingHangGroupID)
        value: 2993
      },
      {
        appNum: 135,
        dataType: '0x03',
        value: 0
      }
    ];
    const msg: any = {
      cmd: 0,
      m: { t: 7, d: data }
    };
    this.GT_command.receiveScadaData(msg);
  }

  // 测试使用结束 ---------------------------------------
}
</script>
<style lang="scss" scoped>
.init-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  .top-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-content: center;
    .top-message {
      line-height: 32px;
    }
  }
  .top-message-error {
    animation: blink 1s infinite;
  }

  @keyframes blink {
    0% {
      background-color: rgba(255, 0, 0, 0.1);
      color: #ff0000;
    }
    50% {
      background-color: rgba(255, 0, 0, 0.3);
      color: #ff0000;
    }
    100% {
      background-color: rgba(255, 0, 0, 0.1);
      color: #ff0000;
    }
  }

  .base-grid-container {
    width: 100%;
    height: 100%;
  }
  .mask-container {
    display: flex;
    justify-content: center;
    align-items: center;
    span {
      font-size: 36px;
    }
  }
}
</style>
